﻿/*
* Author:feitianxinhong
* CreateDate:2013-08-19
* CopyRight:【Tyingsoft】Twilight Software Development Studio ©2013 
* Description:Twi.Msg base on HubSpot messenger
*/

(function () {
    var global = this;
    if (typeof Twi === 'undefined') {
        global.Twi = {};
    }
    Twi.global = global;
    if ($('body').length == 0) {
        document.write('<link href="/Framework/messenger-1.3.5/css/messenger.css" rel="stylesheet" type="text/css" />');
        document.write('<link href="/Framework/messenger-1.3.5/css/messenger-theme-future.css" rel="stylesheet" type="text/css" />');
        document.write('<script src="/Framework/messenger-1.3.5/js/messenger.min.js" type="text/javascript"></script>');
    }
    else {
        $("body").append('<link href="/Framework/messenger-1.3.5/css/messenger.css" rel="stylesheet" type="text/css" />');
        $("body").append('<link href="/Framework/messenger-1.3.5/css/messenger-theme-future.css" rel="stylesheet" type="text/css" />');
        $("body").append('<script src="/Framework/messenger-1.3.5/js/messenger.min.js" type="text/javascript"></script>');
    }
})();

Twi.Msg = {
    Info: function (config) {
        if (typeof config == "string") config = { message: config };
        config = config || {};
        var msgConfig = {};
        Twi.apply(msgConfig,config,{
            message: '操作成功',
            //hideAfter: 3, //3秒后自动关闭
            showCloseButton: true
        });
        $.globalMessenger().post(msgConfig);
    }
    , Error: function (config) {
        if (typeof config == "string") config = { message: config };
        config = config || {};
        var msgConfig = {};
        Twi.apply(msgConfig, config, {
            message: '操作失败',
            type: 'error',
            //hideAfter: 3, //3秒后自动关闭
            showCloseButton: true
        });
        $.globalMessenger().post(msgConfig);
    }
    , Comfirm: function (handler, msg) {
        msg = msg || "执行后数据不能恢复，你确定要执行吗？";
        var messenger;
        messenger = $.globalMessenger().post({
            message: msg,
            actions: {
                retry: {
                    label: '是',
                    action: function () {
                        if (typeof handler == "function") {
                            handler();
                        }
                    }
                },
                cancel: {
                    label: '否',
                    action: function () {
                        return messenger.cancel();
                    }
                }
            }
        });
    }
} //end Twi.Msg